package com.example.mybatisplus.common.utls;

import com.example.mybatisplus.model.domain.Admin;
import com.example.mybatisplus.model.domain.User;
import com.example.mybatisplus.model.domain.WhitelistSetting;
import com.example.mybatisplus.model.dto.UserInfoDTO;
import com.example.mybatisplus.model.dto.UserUpdateDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SecurityUtils {
    public static Admin getCurrentUserInfo() {
        Admin userInfo = SessionUtils.getCurrentUserInfo();
        //模拟登录
        if (userInfo == null) {
            userInfo = new Admin();
            userInfo.setLoginName("模拟");
        }

        return userInfo;
    }

    public static UserUpdateDTO getUserInfo() {
        // 从session获取当前用户
        User currentUser = SessionUtils.getCurrentUserUpdate();
        UserUpdateDTO info = new UserUpdateDTO();
        if(currentUser != null){
            info.setId(currentUser.getIdUser());
            info.setName(currentUser.getNameUser());
            info.setUserType(currentUser.getAuthorizationUser());
            return info;
        }
        return null;
    }
//    public static UserInfoDTO getUserInfo() {
//        // 从session获取当前用户
//        WhitelistSetting currentUser = SessionUtils.getCurrentUser();
//        UserInfoDTO info = new UserInfoDTO();
//        if(currentUser != null){
//            info.setId(currentUser.getId());
//            info.setName(currentUser.getName());
//            info.setUserType(currentUser.getRoleId());
//            return info;
//        }
//        return null;
//    }

}
